<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Spring Boot Cookie示例</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            max-width: 800px;
            margin: 0 auto;
            padding: 20px;
            text-align: center;
        }
        h1 {
            color: #333;
        }
        .btn {
            background-color: #4CAF50;
            border: none;
            color: white;
            padding: 10px 20px;
            text-align: center;
            text-decoration: none;
            display: inline-block;
            font-size: 16px;
            margin: 10px 2px;
            cursor: pointer;
            border-radius: 4px;
        }
        .btn:hover {
            background-color: #45a049;
        }
        .result {
            margin-top: 20px;
            padding: 15px;
            background-color: #f2f2f2;
            border-radius: 4px;
        }
    </style>
</head>
<body>
<h1>Spring Boot Cookie示例</h1>
<p>这个示例展示了如何在Spring Boot应用中设置Cookie。</p>

<button class="btn" onclick="setCookie()">设置Cookie</button>
<button class="btn" onclick="checkCookie()">检查Cookie</button>

<div class="result" id="result"></div>

<script>
    function setCookie() {
        // 调用接口设置Cookie
        fetch('/set-cookie')
            .then(response => response.text())
            .then(data => {
                document.getElementById('result').innerHTML = data;
            })
            .catch(error => {
                document.getElementById('result').innerHTML = '设置Cookie失败: ' + error;
            });
    }

    function checkCookie() {
        // 显示当前页面的所有Cookie
        const cookies = document.cookie;
        if (cookies) {
            document.getElementById('result').innerHTML = '当前Cookie: ' + cookies;
        } else {
            document.getElementById('result').innerHTML = '没有检测到Cookie';
        }
    }
</script>
</body>
</html>